<template>
  <div class="dialog-admin">
    <el-dialog
      :visible.sync="dialogVisible"
      :title="field == 'add' ? '添加设备' : '修改'"
      width="800px"
      @close="handleClose"
      :append-to-body="true"
      custom-class="dialog-copy"
    >
      <el-form
        ref="ruleForm"
        :model="ruleForm"
        :rules="rules"
        label-width="100px"
        class="dialog-ruleForm"
      >
         <el-form-item label="设备ID:" prop="name">
          <el-input v-model="ruleForm.name" clearable />
        </el-form-item>
        <el-form-item label="设备名称:">
          <el-input v-model="ruleForm.name" clearable />
        </el-form-item>
        <el-form-item label="所属分组:" prop="name">
          <el-input v-model="ruleForm.name" clearable />
        </el-form-item>
       
        <el-form-item label="安装位置:">
          <el-input v-model="ruleForm.name" clearable />
        </el-form-item>
        <el-form-item label="备注信息:">
          <el-input v-model="ruleForm.name" type="textarea" :autosize="{ minRows: 1, maxRows: 4}" clearable />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'ProjectDetail',
  props: {
    value: {
      type: Boolean,
      default: false
    },
    field: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      ruleForm: {
        name: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    dialogVisible: {
      get() {
        return this.value // 返回父组件通过 v-model 传递的值
      },
      set(val) {
        this.$emit('close', val) // 当 dialogVisible 变化时，通知父组件更新
      }
    }
  },
  methods: {
    handleClose() {
      this.dialogVisible = false // 关闭弹窗
      this.$emit('close') // 发送关闭事件给父组件
    }
  }
}
</script>
<style scoped lang="scss">
.dialog-ruleForm{
  width: 80%;
  line-height: 60px;
  margin: 0 auto;
}
</style>
